package com.ams.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import com.ams.util.Constants;


public class EncodingFilter implements Filter {

	private FilterConfig config;
	private String encoding=Constants.ENCODING;
    
	
    public EncodingFilter() {
    }

	
	public void destroy() {
		config=null;
		encoding=null;
	}

	
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		System.out.println("encoding filter");
		request.setCharacterEncoding(encoding);
		response.setCharacterEncoding(encoding);
		response.setContentType(Constants.CONTENT_TYPE);
		chain.doFilter(request, response);
	}

	
	public void init(FilterConfig fConfig) throws ServletException {
		config=fConfig;
		encoding=config.getInitParameter("encoding");
	}

}
